# Contributor: psykose <alice@ayaya.dev>
# Maintainer: psykose <alice@ayaya.dev>
pkgname=mold
pkgver=1.3.1
pkgrel=0
pkgdesc="fast modern linker"
url="https://github.com/rui314/mold"
arch="aarch64 x86_64" # only aarch64, x86_64 supported
license="AGPL-3.0" # not specified if -only
makedepends="
	clang
	cmake
	libtbb-dev
	linux-headers
	llvm-dev
	mimalloc2-dev
	openssl-dev
	zlib-dev
	"
checkdepends="
	bash
	dwarf-tools
	grep
	perl
	"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/rui314/mold/archive/refs/tags/v$pkgver.tar.gz"

export SYSTEM_MIMALLOC=1
export SYSTEM_TBB=1
export LTO=1

build() {

	make CC=clang \
		CXX=clang++ \
		PREFIX=/usr \
		CFLAGS="$CFLAGS -O2" \
		CXXFLAGS="$CXXFLAGS -O2"
}

check() {
	# no idea why it fails
	rm -f test/elf/versioned-undef.sh
	rm -f test/elf/z-text.sh
	rm -f test/elf/dt-init.sh
	# not supported on musl
	rm -f test/elf/ifunc*
	rm -f test/elf/preinit-array.sh

	make test
}

package() {
	make DESTDIR="$pkgdir" PREFIX=/usr install
}

sha512sums="
f576d2fcfee5cb3bade5ba24dcdd3020a16131ce7d4c3a00c3f92b94785ed86f3f040a6f5814b9c975c4c3d90a2b8c36a8101d5fbf1bc0a4be316f4a4a6dcefa  mold-1.3.1.tar.gz
"
